#include "iostream"
#include "ImagePublisher.h"
#include "ImageCatcher.h"
#include "ros/ros.h"
using namespace std;

int main(int argc, char** argv) {
	ros::init(argc, argv, "image_publisher");
	ros::NodeHandle nh;

//	使用图像直接分解发送方式，无需运行 composite_publisher 节点
	ImageCatcher ic(2, 1920*2, 1080, "MJPG");
	ic.setFilename("photo_shot");
//	无需显示视频流，请注释以下代码
//	ic.showVideoStream();

	ImagePublisher::ImageTopics imageTopics;
	imageTopics.originImageTopic = "/image_publisher/origin/image_raw";
	imageTopics.leftImageTopic = "/image_publisher/left/image_raw";
	imageTopics.rightImageTopic = "/image_publisher/right/image_raw";
	ImagePublisher::ImagePublisher ip(nh, imageTopics);
//	使用图像转发订阅方式，请运行 composite_publisher 节点，并反注释以下代码
//	ip.publish("/composite_publisher/image_raw");
	while (ros::ok()) {
//		使用图像直接分解发送方式
		ip.publish(ic);
		ros::spinOnce();
	}

//	设置loop_rate可能会使图像滞后严重，在使用loop_rae之前必须声明nodeHandle
//	ros::Rate loop_rate(5);
/*
	while (ros::ok()) {
		int key = waitKey(1);
		ip.setNewFrame(ic.getFrame());
//		ImageCatcher::showFrame(ic.getFrame(), 4, "left frame");
//		ImageCatcher::showFrame(right, 4, "right frame");
		ip.publish();
		ros::spinOnce();
//		loop_rate.sleep();
		if (key == 27) break;
	}
*/
    return 0;
}
